package com.tech.connect.huanzhewan;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ksy.common.utils.BaseAdapter;
import com.ksy.common.utils.BaseHolder;
import com.ksy.common.view.HLineDivider;
import com.tech.connect.R;
import com.tech.connect.fragment.BaseFragment;

import java.util.ArrayList;
import java.util.List;

public class HuanZheWanFaShaoYouFragment extends BaseFragment {

    private ImageView ivMy;
    private TextView tvMy;
    private RecyclerView myRecycler;
    private ImageView ivJoin;
    private TextView tvJoin;
    private RecyclerView joinRecycler;
    private BaseAdapter<String, BaseHolder> myAdapter;
    private BaseAdapter<String, BaseHolder> joinAdapter;
    private List<String> allMyList = new ArrayList<>();
    private List<String> allJoinList = new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.fragment_huanzhewan_fashaoyou, null);
        return view;
    }

    @Override
    protected boolean isShowHeadBar() {
        return true;
    }

    @Override
    protected boolean isFullStateBar() {
        return true;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        getHeadBar().setLeftIcon(R.drawable.icon_back, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.onBackPressed();
            }
        }).setTitle("发烧友").setRightIcon(R.drawable.icon_search, new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        initView(view);
        loadData();
        initMyAdapter();
        initJoinAdapter();
    }


    private void initView(View view) {
        view.findViewById(R.id.llAdd).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        view.findViewById(R.id.llMy).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int visibility = myRecycler.getVisibility();
                if(visibility==View.VISIBLE){
                    myRecycler.setVisibility(View.GONE);
                    ivMy.setImageResource(R.drawable.icon_arrow_right);
                }else {
                    myRecycler.setVisibility(View.VISIBLE);
                    ivMy.setImageResource(R.drawable.icon_arrow_down);
                }
            }
        });
        view.findViewById(R.id.llJoin).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int visibility = joinRecycler.getVisibility();
                if(visibility==View.VISIBLE){
                    joinRecycler.setVisibility(View.GONE);
                    ivJoin.setImageResource(R.drawable.icon_arrow_right);
                }else {
                    joinRecycler.setVisibility(View.VISIBLE);
                    ivJoin.setImageResource(R.drawable.icon_arrow_down);
                }
            }
        });
        ivMy = view.findViewById(R.id.ivMy);
        tvMy = view.findViewById(R.id.tvMy);
        myRecycler = view.findViewById(R.id.myRecycler);
        ivJoin = view.findViewById(R.id.ivJoin);
        tvJoin = view.findViewById(R.id.tvJoin);
        joinRecycler = view.findViewById(R.id.joinRecycler);
        myRecycler.addItemDecoration(new HLineDivider());
        myRecycler.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });
        joinRecycler.addItemDecoration(new HLineDivider());
        joinRecycler.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });
    }

    private void initMyAdapter() {
        if (myAdapter == null) {
            myAdapter = new BaseAdapter<String, BaseHolder>(R.layout.item_layout_team, allMyList, 6) {
                @Override
                protected void convert(BaseHolder helper, int position) {

                }
            };
            myRecycler.setAdapter(myAdapter);
        }
        myAdapter.notifyDataSetChanged();
    }

    private void initJoinAdapter() {

        if (joinAdapter == null) {
            joinAdapter = new BaseAdapter<String, BaseHolder>(R.layout.item_layout_team, allJoinList, 3) {
                @Override
                protected void convert(BaseHolder helper, int position) {

                }
            };
            joinRecycler.setAdapter(joinAdapter);
        }
        joinAdapter.notifyDataSetChanged();
    }

    private void loadData() {

    }
}
